//
//  DoctorApply_ViewController.m
//  International_Hospital
//
//  Created by LiYiLin on 16/7/4.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "DoctorApply_ViewController.h"
#import "DoctorApplyModel.h"
#import "DoctorsApplyCell.h"
#import "DoctorDetailController.h"

@interface DoctorApply_ViewController ()<UITableViewDataSource,UITableViewDelegate>

//tableView
@property (nonatomic,weak) UITableView *tableView;

//医生信息数组
@property (nonatomic, strong)NSArray *doctorsInfoArray;

@property (nonatomic, strong) DoctorDetailController *vc;

@end

@implementation DoctorApply_ViewController

#pragma mark
#pragma mark - 懒加载控制器
- (DoctorDetailController *)vc{
    
    if (!_vc) {
        
        _vc = [[DoctorDetailController alloc] init];
        
    }
    
    return _vc;
    
}

#pragma mark
#pragma mark - 重写doctorsInfoArray set方法  刷新
- (void)setDoctorsInfoArray:(NSArray *)doctorsInfoArray{
    
    _doctorsInfoArray = doctorsInfoArray;
    
    [self.tableView reloadData];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];

    //设置并添加子控件
    [self setupUI];
    
    //加载数据
    [DoctorApplyModel getDataWithSuccess:^(NSArray *array) {
        
        self.doctorsInfoArray = array;
        
    } error:^{
        
        NSLog(@"DoctorApplyModel 数据错误");
        
    }];
    
}

#pragma mark
#pragma mark - 设置并添加子控件
- (void)setupUI{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    
    self.tableView = tableView;
    
    //设置代理
    tableView.delegate = self;
    
    tableView.dataSource = self;
    
    [self.view addSubview:tableView];
    
    //注册cell
    [self.tableView registerClass:[DoctorsApplyCell class] forCellReuseIdentifier:@"doctor_cell"];
    
    //设置行高
    self.tableView.rowHeight = 100;
    
    //关闭垂直滚动条
    self.tableView.showsVerticalScrollIndicator = NO;
    
}

#pragma mark
#pragma mark - 代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.doctorsInfoArray.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DoctorsApplyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"doctor_cell" forIndexPath:indexPath];
    
    DoctorApplyModel *model = self.doctorsInfoArray[indexPath.row];
    
    cell.model = model;
    
    NSArray *statuArray = @[@"审核中",@"已就诊",@"审核中",@"已就诊",@"审核中",@"已就诊",@"审核中",@"已就诊",@"审核中",@"已就诊",@"审核中",@"已就诊",@"审核中",@"已就诊",@"审核中"];
    
    cell.statuStr = statuArray[indexPath.row];
    
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;

}

#pragma mark
#pragma mark - 点击cell跳入的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    self.vc.view.backgroundColor = [UIColor whiteColor];
    
    self.vc.title = @"预约医生信息详情";
    
    self.vc.model = self.doctorsInfoArray[indexPath.row];
    
    NSArray *statuArray = @[@"审核中",@"已就诊",@"审核中",@"已就诊",@"审核中",@"已就诊",@"审核中",@"已就诊",@"审核中",@"已就诊",@"审核中",@"已就诊",@"审核中",@"已就诊",@"审核中"];
    
    self.vc.statuStr2 = statuArray[indexPath.row];
    
    [self.navigationController pushViewController:self.vc animated:YES];
    
}

@end
